home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
DRDOBBS.ZIP
/
UC993.TXT
< prev
next >
Wrap
Text File
|
1993-10-08
|
16KB
|
388 lines
_UNDOCUMENTED CORNER_
edited by Andrew Schulman
written by Pete Davis
[LISTING ONE]
/* WHSTRUCT.H--Windows Help File Internal Records--Pete Davis and Ron Burk,
June 1993. See "Undocumented Corner," DDJ, September 1993 */
typedef unsigned long DWORD;
typedef unsigned int WORD;
typedef unsigned char BYTE;
#define HELP_MAGIC 0x00035F3FL
/* Help file Header record */
typedef struct HELPHEADER {
DWORD MagicNumber; /* 0x00035F3F */
long WHIFS; /* File offset of WHIFS header */
long Negative1;
long FileSize; /* Size of entire .HLP File */
} HELPHEADER;
/* File Header for WHIFS files */
typedef struct FILEHEADER {
long FilePlusHeader; /* File size including this header */
long FileSize; /* File size not including header */
char TermNull;
} FILEHEADER;
/* Help Directory BTREE */
typedef struct WHIFSBTREEHEADER {
char Magic[18]; /* Not exactly magic for some .MVB files */
char Garbage[13];
int MustBeZero; /* Probably shows up when Help > ~40 megs */
int NSplits; /* Number of page split Btree has suffered */
int RootPage; /* Page # of root page */
int MustBeNegOne; /* Probably shows up when B-Tree is HUGE!! */
int TotalPages; /* total # to 2Kb pages in Btree */
int NLevels; /* Number of levels in this Btree */
DWORD TotalWHIFSEntries;
} WHIFSBTREEHEADER;
/* Modified B-Tree Node header to handle a pointer to the page */
typedef struct BTREENODEHEADER {
WORD Signature; /* Signature word */
int NEntries; /* Number of entries */
int PreviousPage; /* Index of Previous Page */
int NextPage; /* Index of Next Page */
char *BTData; /* Pointer to B-Tree's data */
} BTREENODEHEADER;
/* Modified B-Tree Index header to handle a pointer to the page */
typedef struct BTREEINDEXHEADER {
WORD Signature; /* Signature word */
int NEntries; /* Number of entries in node */
char *IdxData;
} BTREEINDEXHEADER;
/* Phrase header for uncompressed |Phrases file */
typedef struct PHRASEHDR {
int NumPhrases; /* Number of phrases in table */
WORD OneHundred; /* 0x0100 */
} PHRASEHDR;
/* Phrase header for compressed |Phrases file */
typedef struct ALTPHRASEHDR {
int NumPhrases; /* Number of phrases in table */
WORD OneHundred; /* 0x0100 */
long PhrasesSize; /* Amount of space uncompressed phrases requires */
} ALTPHRASEHDR;
/* Flags for |SYSTEM header Flags field below: Unfortunately, none of these
flags are particularly solid. The 0x0004 works MOST of the time. Another
flag, 0x0008, appears both in Win32 .HLP files, and in files with Phrase
compression but without LZ77 compression. */
#define NO_COMPRESSION_310 0x0000
#define COMPRESSION_310 0x0004
#define SYSFLAG_300 0x000A
/* Header for |SYSTEM file */
typedef struct SYSTEMHEADER {
BYTE Magic; /* 0x6C */
BYTE Version; /* Version # */
BYTE Revision; /* Revision code */
BYTE Always0; /* Unknown */
WORD Always1; /* Always 0x0001 */
DWORD GenDate; /* Date/Time that the help file was generated */
WORD Flags; /* Values seen: 0x0000 0x0004, 0x0008, 0x000A */
} SYSTEMHEADER;
/* Types for SYSTEMREC RecordType below: note that other record types,
such as 0x0A, 0x0B, 0x0C, 0x0D, shown up in the large .MVB files used
by the MSDN CD-ROM and Cinemania products. */
#define HPJ_TITLE 0x0001 /* Title from .HPJ file */
#define HPJ_COPYRIGHT 0x0002 /* Copyright notice from .HPJ file */
#define HPJ_CONTENTS 0x0003 /* Contents= from .HPJ */
#define MACRO_DATA 0x0004 /* RData = 4 nulls if no macros */
#define ICON_DATA 0x0005 /* Data for Icon */
#define HPJ_SECWINDOWS 0x0006 /* Secondary window info in .HPJ */
#define HPJ_CITATION 0x0008 /* Citation= under [OPTIONS] */
/* Secondary Window Record following type 0x0006 System Record */
typedef struct SECWINDOW {
WORD Flags; /* Flags (See Below) */
BYTE Type[10]; /* Type of window */
BYTE Name[9]; /* Window name */
BYTE Caption[51]; /* Caption for window */
WORD X; /* X coordinate to start at */
WORD Y; /* Y coordinate to start at */
WORD Width; /* Width to create for */
WORD Height; /* Height to create for */
WORD Maximize; /* Maximize flag */
BYTE Rgb[3]; /* RGB for background */
BYTE Unknown1; /* No known use */
BYTE RgbNsr[3]; /* RGB for non scrollable region */
BYTE Unknown2; /* No known use */
} SECWINDOW;
/* Values for Secondary Window Flags */
#define WSYSFLAG_TYPE 0x0001 /* Type is valid */
#define WSYSFLAG_NAME 0x0002 /* Name is valid */
#define WSYSFLAG_CAPTION 0x0004 /* Ccaption is valid */
#define WSYSFLAG_X 0x0008 /* X is valid */
#define WSYSFLAG_Y 0x0010 /* Y is valid */
#define WSYSFLAG_WIDTH 0x0020 /* Width is valid */
#define WSYSFLAG_HEIGHT 0x0040 /* Height is valid */
#define WSYSFLAG_MAXIMIZE 0x0080 /* Maximize is valid */
#define WSYSFLAG_RGB 0x0100 /* Rgb is valid */
#define WSYSFLAG_RGBNSR 0x0200 /* RgbNsr is valid */
#define WSYSFLAG_TOP 0x0400 /* On top was set in HPJ file */
/* Help Compiler 3.1 System record. Multiple records possible */
typedef struct SYSTEMREC {
WORD RecordType; /* Type of Data in record */
WORD DataSize; /* Size of RData */
char *RData; /* Raw data (Icon, title, etc) */
} SYSTEMREC;
/* Header for |TOMAP file */
typedef struct TOMAPHEADER {
long IndexTopic; /* Index topic for help file */
long Reserved[15];
int ToMapLen; /* Number of topic pointers */
long *TopicPtr; /* Pointer to all the topics */
} TOMAPHEADER;
[LISTING TWO]
/* HELPDIR.C -- List all internal files with a Windows .HLP file.
WHIFS = Windows Help Internal File System -- Pete Davis, June 1993
bcc helpdir.c
See "Undocumented Corner," DDJ, September 1993 */
#pragma pack(1)
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "whstruct.h"
#define PAGE_SIZE 1024L /* 1k pages -- must be long! */
void fail(const char *s) { puts(s); exit(1); }
int main(int argc, char *argv[]) {
HELPHEADER HelpHdr;
WHIFSBTREEHEADER WHIFSHdr;
BTREENODEHEADER WHIFSNode;
int file, aPage, c;
long WHIFSStart, FileOffset;
FILE *HelpFile;
if ((HelpFile=fopen(argv[1], "rb")) == NULL)
fail("can't open file");
/* Get Help header, go to WHIFS and get WHIFS Header */
fread(&HelpHdr, sizeof(HelpHdr), 1, HelpFile);
if (HelpHdr.MagicNumber != HELP_MAGIC)
fail("not a Windows help file");
fseek(HelpFile, HelpHdr.WHIFS, SEEK_SET);
fread(&WHIFSHdr, sizeof(WHIFSHdr), 1, HelpFile);
/* WHIFS starts after the WHIFSHdr */
WHIFSStart = HelpHdr.WHIFS + sizeof(WHIFSHdr);
file=1;
/* Goto WHIFS Root */
fseek(HelpFile, WHIFSStart + (PAGE_SIZE * WHIFSHdr.RootPage), SEEK_SET);
/* Find the first leaf node */
while (file < WHIFSHdr.NLevels) {
/* if it's not a leaf, we don't need last 2 fields */
fread(&WHIFSNo